package com.stylefeng.guns.modular.operation_log.controller;

import com.stylefeng.guns.core.base.controller.BaseController;
import com.stylefeng.guns.modular.operation_log.model.MOperationLog;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import com.stylefeng.guns.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import com.stylefeng.guns.modular.operation_log.service.IMOperationLogService;

import javax.servlet.http.HttpServletResponse;

/**
 * 设备添加日志控制器
 *
 * @author fengshuonan
 * @Date 2020-10-01 17:41:59
 */
@Controller
@RequestMapping("/opertationLog")
public class OpertationLogController extends BaseController {

    private String PREFIX = "/operation_log/opertationLog/";

    @Autowired
    private IMOperationLogService opertationLogService;

    /**
     * 跳转到设备添加日志首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "opertationLog.html";
    }

    /**
     * 跳转到添加设备添加日志
     */
    @RequestMapping("/opertationLog_add")
    public String opertationLogAdd() {
        return PREFIX + "opertationLog_add.html";
    }

    /**
     * 跳转到修改设备添加日志
     */
    @RequestMapping("/opertationLog_update/{opertationLogId}")
    public String opertationLogUpdate(@PathVariable Integer opertationLogId, Model model) {
        MOperationLog opertationLog = opertationLogService.selectById(opertationLogId);
        model.addAttribute("item",opertationLog);
        LogObjectHolder.me().set(opertationLog);
        return PREFIX + "opertationLog_edit.html";
    }

    /**
     * 获取设备添加日志列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(@RequestParam(value = "page",defaultValue = "0") Integer page,
                       @RequestParam(value = "limit",defaultValue = "20") Integer limit) {
        return opertationLogService.list(page,limit);
    }

    /**
     * 到处表格
     * @return
     */
    @RequestMapping(value = "/export")
    @ResponseBody
    public void exportExcel(HttpServletResponse response) {
        opertationLogService.export(response);
    }
}
